package com.warehouse.service.impl;

import com.warehouse.entity.Supply;
import com.warehouse.entity.SupplyExample;
import com.warehouse.mapper.SupplyMapper;
import com.warehouse.service.SupplyService;
import com.warehouse.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @program: warehouse
 * @description:
 * @author: xiaojiu
 * @create: 2021-01-12 21:19
 */
@Service
public class SupplyServiceImpl implements SupplyService {
    @Autowired(required = false)
    private SupplyMapper supplyMapper;
    @Autowired
    private IdWorker idWorker;
    @Autowired(required = false)
    SupplyExample example;

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Supply> selectAll() {

        List<Supply> supplies = supplyMapper.selectByExample(example);
        return supplies;
    }

    /**
     * 删除
     * @param suPNum
     * @return
     */
    @Override
    public boolean delsupply(String id) {
        Boolean aBoolean = supplyMapper.deleteByNum(id);
        if(aBoolean){
            return true;
        }
        return false;
    }

    /**
     * 添加
     * @param supply
     * @return
     */
    @Override
    public boolean insertSupply(Supply supply) {

        String id=idWorker.nextId()+"";
        supply.setId(id);
        supply.setCreateTime(new Date());
        int i = supplyMapper.insertSelective(supply);
        if (i>0){
           return true;
        }
        return false;
    }

    @Override
    public boolean editSupply(Supply supply) {
        int i = supplyMapper.updateByPrimaryKeySelective(supply);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public List<Supply> findSupply(Supply supply) {
        List<Supply> supplies=supplyMapper.findSupply(supply);
        return supplies;
    }
}
